<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var wordPattern = function(pattern, str) {
				var arr = str.split(' ');
				if (pattern.length != arr.length) return false;
				for (var i = 0; i < pattern.length; i++) {
					if (pattern.indexOf(pattern[i]) != arr.indexOf(arr[i])) {
						return false;
					}
				}
				return true;
			};
			console.log(wordPattern("abba", "dog cat cat dog"));
		</script>
	</body>
</html>
